package com.wq.hardcodeaudiovideostudy;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.wq.hardcodeaudiovideostudy.audiorecord.AudioRecorder;
import com.wq.hardcodeaudiovideostudy.permission.RequestPermissionManager;

import java.text.SimpleDateFormat;
import java.util.Date;


public class MainActivity extends AppCompatActivity {

    private static final String TAG  = "wq892373445";
    private AudioRecorder audioRecorder;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RequestPermissionManager.startRequestPermission(this);
        audioRecorder = AudioRecorder.getInstance();
    }

    /**
     * 开始录音
     * @param view
     */
    public void onStartAudioRecordRecording(View view) {
        //初始化录音
        String fileName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
        Log.d(TAG, "===fileName==="+fileName);
        audioRecorder.createDefaultAudio(fileName);
        audioRecorder.startRecord(null);
    }

    /**
     * 停止录音
     * @param view
     */
    public void onStopRecording(View view) {
        //停止录音
        audioRecorder.stopRecord();
    }

    /**
     * 暂停录音
     * @param view
     */
    public void onPauseRecording(View view) {
    }

    /**
     * 播放录音
     * @param view
     */
    public void onPlayRecording(View view) {
    audioRecorder.playPCM("/storage/emulated/0/abctest/pcm/20200530103348.pcm");
    }
}
